package com.universal_library.activity;

import android.support.annotation.StringRes;
import android.view.View;

import com.universal_library.R;
import com.universal_library.weight.MyTitleBar;

/**
 * Created by solin on 2018/1/29.
 * 带返回键的 actiivyt
 */

public abstract class BaseBackActivity extends BaseActivity {

    protected MyTitleBar mTitleBar;

    @Override
    protected void initWindow() {
        super.initWindow();
        initTitle();
    }

    /**
     * 初始化标题
     */
    private void initTitle() {
        mTitleBar = (MyTitleBar) findViewById(R.id.mTitleBar);
        //标题文字
        mTitleBar.setTitle(getTitleRes());
        //标题颜色
        mTitleBar.setTitleColor(getTitlecolor());
        //右侧图片
        mTitleBar.setIcon(getMIconRes());
        //关闭的图片
        mTitleBar.setCloseIcon(getCloseRes());
        //返回按钮图片
        mTitleBar.setBackIcon(getBackRes());
        //右侧图片点击事件
        mTitleBar.setIconOnClickListener(getIconClickListener());
        //返回按钮的点击事件
        mTitleBar.setBackClickListener(getBackClickListener());
        //关闭按钮的点击事件
        mTitleBar.setCloseListener(getCloseClickListener());
        //设置标题背景色
        mTitleBar.setBackGroundColor(getBackgroundColor());
        //将标题设置成图片  ---
        mTitleBar.setMTitleBackGroudIcon(getMtitleTextViewIcon());
    }

    /**
     * 背景色
     *
     * @return
     */
    protected int getBackgroundColor() {
        return R.color.index_red;
    }

    /**
     * 标题重新赋值
     *
     * @param titleBarTitle
     */
    protected void setwTitleBarTitle(@StringRes int titleBarTitle) {
        mTitleBar.setTitle(titleBarTitle);
    }

    //返回按钮图片
    protected int getBackRes() {
        return R.mipmap.ic_turn_back_img;
    }

    //标题
    protected abstract int getTitleRes();

    //标题颜色
    protected int getTitlecolor() {
        return 0;
    }

    protected int getMIconRes() {
        return 0;
    }

    //关闭的图片
    protected int getCloseRes() {
        return 0;
    }

    //标题是否显示图片
    public int getMtitleTextViewIcon() {
        return 0;
    }

    protected View.OnClickListener getIconClickListener() {
        return null;
    }

    protected View.OnClickListener getCloseClickListener() {
        return null;
    }

    protected View.OnClickListener getBackClickListener() {
        return new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        };
    }
}
